﻿/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#include "../import/head.h"
#include "../global/head.h"
#include "../macro/head.h"
#include "../impl/head.h"
#include "sys_data.h"
#include "aio_data.h"
#include "aio_key.h"

///////////////////////////////////////////////////////////////////////////////////////////////////

namespace xos_aio
{

    sys_data::sys_data( xos_container::i_container * pContainer ) : m_pContainer( pContainer )
    {
        m_pCallbackObj = 0;
        m_pTime = 0;
        m_pMisc = 0;
        m_pCrt = 0;
    }

    sys_data::~sys_data()
    {
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 

    int sys_data::init()
    {
        int nRet = 0;

        if( 0 == nRet )
        {
            nRet = m_pContainer->xos()->create( xos::i_xos::XOS_OBJ_TIME, ( void ** )&m_pTime );
        }

        if( 0 == nRet )
        {
            nRet = m_pContainer->xos()->create( xos::i_xos::XOS_OBJ_MISC, ( void ** )&m_pMisc );
        }

        if( 0 == nRet )
        {
            nRet = m_pContainer->xos()->create( xos::i_xos::XOS_OBJ_CRT, ( void ** )&m_pCrt );
        }

        if( 0 == nRet )
        {
            m_pContainer->log()->add_log_module( AIO_LOG, 1 );
            m_pContainer->log()->add_log_module( AIO_LOG, 2 );
            m_pContainer->log()->add_log_module( AIO_LOG, 3 );
            m_pContainer->log()->add_log_module( AIO_LOG, 4 );
        }

        if( 0 == nRet )
        {
            nRet = aio_data::init_all();
        }

        if( 0 == nRet )
        {
            nRet = aio_key::init_all();
        }

        if( 0 == nRet )
        {
            nRet = aio_impl::init_all();
        }

        return nRet;
    }

    int sys_data::term()
    {
        int nRet = 0;

        aio_impl::term_all();
        aio_key::term_all();
        aio_data::term_all();

        xos_stl::release_interface( m_pTime );
        xos_stl::release_interface( m_pMisc );
        xos_stl::release_interface( m_pCrt );

        m_pCallbackObj = 0;
        m_pContainer = 0;

        return nRet;
    }

} // xos_aio
